package Presentation.GraphicUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class AddNewMovieScreen extends MovieSystemPanel{

    private JTextField      m_name;   //this field is the Movie ID
    private JTextField      m_director;
    private JTextField      m_year;
    private JTextField      m_length;
    private JTextField      m_country;
    private JTextField      m_genres;
    private JTextField      m_actors;
    private static JButton	submitButton;

    public AddNewMovieScreen(MainScreen mainScreen){
        super(mainScreen);

        JLabel msg=new JLabel("Please fill all the fields, than click the 'Submit' button");

        m_name = new JTextField(15);
        JLabel movieNameLabel = new JLabel("Movie Name: ");
        
        m_director = new JTextField(15);
        JLabel directorNameLabel = new JLabel("Director Name: ");

         m_year = new JTextField(15);
        JLabel movieYearLabel = new JLabel("Movie published Year: ");

         m_length = new JTextField(15);
        JLabel movieLengthLabel = new JLabel("Movie Length: ");

         m_country = new JTextField(15);
        JLabel movieCountryLabel = new JLabel("Movie Country: ");

        m_genres = new JTextField(30);
        JLabel movieGenresLabel = new JLabel("Movie Ganers (separated by comma): ");

        m_actors = new JTextField(30);
        JLabel movieActorsLabel = new JLabel("Movie Actors (separated by comma): ");

        add(msg);

        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel.add(movieNameLabel);
		panel.add(m_name);
        add(panel);

        panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel.add(directorNameLabel);
		panel.add(m_director);
        add(panel);

        panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel.add(movieYearLabel);
		panel.add(m_year);
        add(panel);

        panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel.add(movieLengthLabel);
		panel.add(m_length);
        add(panel);

        panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel.add(movieCountryLabel);
		panel.add(m_country);
        add(panel);

        panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel.add(movieGenresLabel);
		panel.add(m_genres);
        add(panel);

        panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		panel.add(movieActorsLabel);
		panel.add(m_actors);
        add(panel);

        panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		setVisible(true);
		submitButton = new JButton("Submit");
		panel.add(submitButton);
		add(panel);

        run();

    }

    private void run(){
        submitButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				try{
					//todo check that the fields are not empty!

                    m_controller.addNewMovie(m_name.getText(),m_director.getText(),m_year.getText(),Integer.parseInt(m_length.getText()),m_country.getText(),m_genres.getText(),m_actors.getText());
                    JOptionPane.showMessageDialog(m_mainScreen,"Movie was added successfully");
                    m_mainScreen.setActivePanel(MainScreen.MAIN_MENU);
                }
                catch(Exception ex)	{
               /*   initFileds(); */
                    JOptionPane.showMessageDialog(m_mainScreen, ex.getMessage());
                }
        }
        });
    }

    public void setUp(){
         m_name.setText("");
         m_director.setText("");
         m_year.setText("");
         m_length.setText("");
         m_country.setText("");
         m_genres.setText("");
         m_actors.setText("");
    }
}
